/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.example.customize.api;

import com.example.customize.api.base.BaseApi;
import com.example.customize.entity.User;
import com.example.customize.entity.UserQuery;
import com.example.customize.entity.UserVo;
import com.example.customize.entity.base.dto.Page;
import com.example.customize.service.simple.UserService;
import com.example.customize.util.ApiResponse;
import com.example.customize.util.ApiResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * user Api
 * @author robot
 * @version 2020-05-27
 */
@RestController
public class UserApi extends BaseApi {

	@Autowired
	private UserService userService;

	@ApiOperation(value="查询单个User")
	@RequestMapping(value = "/user/query",method = {RequestMethod.GET})
	public ApiResponse<User> query(@ApiParam(value = "id",required = true) @RequestParam(required = true) String id) {
		return ApiResponse.success(userService.query4id(id));
	}

	@ApiOperation(value="创建User")
	@RequestMapping(value = "/user/create",method = {RequestMethod.POST})
	public ApiResponse<Boolean> create(@ModelAttribute User user){
		return ApiResponse.success(userService.create(user));
	}

	@ApiOperation(value="修改User信息")
	@RequestMapping(value = "/user/modify",method = {RequestMethod.POST})
	public ApiResponse<Boolean> modify(@ModelAttribute User user){
		return ApiResponse.success(userService.modify(user));
	}

	@ApiOperation(value="删除User信息")
	@RequestMapping(value = "/user/remove",method = {RequestMethod.POST})
	public ApiResponse<Boolean> remove(@ApiParam(value = "id",required = true) @RequestParam(required=true)String id){
		return ApiResponse.success(userService.remove(id));
	}
	
	@ApiOperation(value="分页查询User信息")
	@RequestMapping(value = "/user/pagequery",method = {RequestMethod.POST})
	public ApiResponse<Page<UserVo>> query4page(@RequestBody UserQuery userQuery) {
		try {
			Page<UserVo> querypage = userService.query4page(userQuery);
			return ApiResponse.success(querypage);
		} catch (Exception e) {
			logger.error("分页查询User信息,异常："+e.getMessage(),e);
			return ApiResponse.fail(ApiResponseResult.ERROR);
		}
	}

}